package oa.hleast.xswl.utils;

import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ShortUrlUtil {

    public static String getShortUrl(String longUrl) {

        String urlCodeShortUrl = URLUtil.encode(longUrl);

        String url = "https://is.gd/create.php?format=simple&url=" + urlCodeShortUrl;

        String shortUrl = HttpUtil.get(url);

        log.info("longUrl = {}, urlCodeShortUrl = {}  ,shortUrl  = {}", longUrl, urlCodeShortUrl, shortUrl);
        return shortUrl;
    }

    public static void main(String[] args) {
        String longUrl = "https://wl.shuzizg.com/wl_cloud/#/venue/reserve?id=1";
        System.out.println("shortUrl = " + ShortUrlUtil.getShortUrl(longUrl));
    }
}

